home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / oper_sys / quartz / quartz10.lha / src / runtime / internal.h < prev    next >
C/C++ Source or Header  |  1990-04-29  |  3KB  |  130 lines

  1. /* Internal data structures needed by the thread package */  
  2.  
  3. #define ThreadsPerBunch        20
  4. #define ThreadThreshold     (ThreadsPerBunch*2)
  5.  
  6. typedef struct ready_queue {
  7.     SpinLock lock;
  8.     Thread *started;
  9.     SynchProfile *empty;
  10.     } ReadyQ;
  11.  
  12. /* shared info per processor: only for profiling, for now */
  13. typedef struct processor {
  14.     Thread *curThread;                /* DONT MOVE */
  15.     SynchProfile *synchList;        /* the synch obj's I created */
  16.  
  17.     SpinLock profLock;
  18.     int numSamples;
  19.     usclk_t lastSample;
  20.  
  21.     Thread idleThread;
  22.     IdStackEntry idStack[InitIdStackSize];
  23.     } Processor;
  24.  
  25. /* private information per processor not accessed by anyone else */
  26. typedef struct private_proc {
  27.     int *sp;                    /* DONT MOVE -- see startup() */
  28.     int *ebp;                    /* DONT MOVE -- see startup() */
  29.     int seed;
  30.     Thread *thread;                /* DONT MOVE */
  31.  
  32.     Processor *proc;
  33.     Thread *idleThread;
  34.  
  35.     int myId;
  36.     ReadyQ *lastLook;
  37.     ReadyQ *putQ;
  38.  
  39.     SynchProfile *freeSynch;    /* free list of synch objects */
  40.     Thread *deadThreads;
  41.             /* not used if I'm profiling */
  42.     int deadCount;
  43.     Thread *deadMiddle;        /* valid only if count > ThreadsPerBunch */
  44.  
  45.     } PrivateProcessor;
  46.  
  47. extern private PrivateProcessor pP;
  48. extern shared Processor processorList[];
  49. extern int processGroup;
  50. extern int affinity;
  51.  
  52. void ThreadpoolInit(), ThreadpoolGet(), ThreadpoolPut();
  53.  
  54. Stack *StackpoolGet();
  55. void StackpoolPut(), StackpoolInit(), KillAll();
  56. void MFork(), ProcessorListInit(), PrivProcessorInit();
  57.  
  58. /* A few nasty macros -- called from a bunch of places, and too
  59. frequently to set off in a function call */
  60.  
  61. #define ThreadAlloc(t) { \
  62.     pP.deadCount--; \
  63.     if (!(t = pP.deadThreads)) {\
  64.         ThreadpoolGet(); \
  65.         t = pP.deadThreads;\
  66.         }\
  67.     pP.deadThreads = t->next;\
  68.     }
  69.  
  70. #define ThreadPut(t,l) ((t)->next = *(l), *(l) = (t))
  71. #define TF(t) { \
  72.     ThreadPut(t, &pP.deadThreads); \
  73.     if (++pP.deadCount == (ThreadsPerBunch + 1)) \
  74.         pP.deadMiddle = pP.deadThreads; \
  75.     else if (pP.deadCount == ThreadThreshold) \
  76.         ThreadpoolPut(); \
  77.     }
  78.  
  79. #ifdef PROFILE
  80.  
  81. #define ReadyQPut(t) { \
  82.     AddNominal(); \
  83.     TSetStateReady(t); \
  84.     SpinLockAcquire(&(pP.putQ->lock)); \
  85.     ThreadPut(t, &(pP.putQ->started)); \
  86.     SpinLockRelease(&(pP.putQ->lock)); \
  87.     }
  88.  
  89. #define ThreadFree(t) { \
  90.     if ((t)->p) t->p->status = DISCARDED; \
  91.     else { TF(t); }  \
  92.     }
  93.  
  94. #define Block(l)        MY_BLOCK(l)
  95. #define BlockNoProf(l)  (SetStateBlocked(), NP_BLOCK(l))
  96.  
  97. #else
  98.  
  99. #define ReadyQPut(t) { \
  100.     SpinLockAcquire(&(pP.putQ->lock)); \
  101.     ThreadPut(t, &(pP.putQ->started)); \
  102.     SpinLockRelease(&(pP.putQ->lock)); \
  103.     }
  104.  
  105. #define ThreadFree(t) TF(t)
  106. #define Block(l)    NP_BLOCK(l)
  107. #define BlockNoProf(l)    NP_BLOCK(l)
  108. #endif
  109.  
  110. #define MyShmalloc(type,n)    (type *)myshmalloc((unsigned)(sizeof(type) * (n)))
  111.  
  112. void TooSmall();
  113. char *shmalloc(), *myshmalloc();
  114.  
  115. #ifdef DEBUG
  116. #define ASSERT(c)    if (!(c)) { printf("FAILED: %s\n","c"); abort();} else
  117. #else
  118. #define ASSERT(c)
  119. #endif
  120.  
  121. #define SpinLockType 0x12345678
  122. #define SynchProfileType 0x23456789
  123. #define ChildDataType 0x3456789a
  124. #define ConcurrentDataType 0x456789ab
  125. #define StackType 0x56789abc
  126. #define ThreadType 0x6789abcd
  127. #define BarrierType 0x789abcde
  128. #define LockType 0x89abcdef
  129. #define ConditionType 0x9abcdef1
  130.